import { defineStore } from "pinia";
import {regetTaskList} from "../../api/tasks";
import dayjs from "dayjs";
import { TaskForm } from '../../view/tasks/dialogForm.vue';
import { TaskState } from "./types/type";
import { getTasklist ,setTasklist,removeTasklist} from "@/utils/task";
import { fa } from "element-plus/es/locales.mjs";
export let taskStore: any = defineStore("TaskStore", {
  state: ():TaskState  => {
    return {
      taskList:[],
      selectedDate:'',
      dialogFlag: false,
      flag:false,
    }
  },
  actions: {
    async getTaskList() {
      let { data } = await regetTaskList();
      removeTasklist();
      setTasklist(JSON.stringify(data));
      this.taskList = JSON.parse(getTasklist() || '[]');
      this.taskList = data;
    },

    openDialog(date?: string) {
      this.selectedDate = date || dayjs().format('YYYY-MM-DD HH:mm:ss')
      this.dialogFlag = true
    },
    closeDialog() {
      this.dialogFlag = false;
      this.selectedDate = "";
    },

    setFlag(){
      this.flag = !this.flag
    }
  },
  getters: {},
});
